package com.jn.web;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @ClassName LoginController
 * @Description LoginController负责打开登录页面(GET请求)和登录出错页面(POST请求)
 *              真正登录的POST请求由Filter完成
 * @author liuxd
 * @date 2013年8月27日 上午10:57:55
 * 
 */
@Controller
@RequestMapping(value = "/login")
public class LoginController {
	private static Logger logger = LoggerFactory
			.getLogger(LoginController.class);

	@RequestMapping(method = RequestMethod.GET)
	public String login() {
		return "common/login";
	}

	@RequestMapping(value = "/main", method = RequestMethod.GET)
	public String main() {
		return "common/main";
	}

	/**
	 * @Title fail
	 * @Description 1、model为springmvc内置对象,以键值对的方式存储数据
	 *              在转发时,会调用request.setAttribute方法将数据写入,在页面可以获取
	 *              2、@RequestParam(FormAuthenticationFilter
	 *              .DEFAULT_USERNAME_PARAM) String userName
	 *              可以获取FormAuthenticationFilter
	 *              .DEFAULT_USERNAME_PARAM的值传递给userName 3、@RequestParam还有一个用法
	 * @RequestParam(value = "page", defaultValue = "1") int pageNumber
	 *                     是从request对象中获取attribute
	 *                     value值为传递的key值，将该key对应的value传递给pageNumber
	 *                     如果没有找到该key，则pageNumber默认defaultValue 1
	 *                     4、参数还可以有request、response、session等servlet对象
	 * @param userName
	 * @param model
	 * @return
	 * @throws
	 */
	@RequestMapping(method = RequestMethod.POST)
	public String fail(
			@RequestParam(FormAuthenticationFilter.DEFAULT_USERNAME_PARAM) String userName,
			Model model) {
		model.addAttribute(FormAuthenticationFilter.DEFAULT_USERNAME_PARAM,
				userName);
		return "common/login";
	}

}
